package com.guigu.servlet;

import com.google.gson.Gson;
import com.guigu.bean.BookBean;
import com.guigu.dao.BookDao;
import com.guigu.mapper.BookMapper;
import com.guigu.util.BookMapperFactory;
import com.ly.common.bean.Result;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@WebServlet(name = "AddServlet", value = "/Add.do")
public class AddServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");
        Map<String,Object> params = new HashMap<>();
        String name = request.getParameter("name");
        params.put("name",name);
        String press = request.getParameter("press");
        String date = request.getParameter("date");
        String author = request.getParameter("author");
        Integer count = Integer.parseInt( request.getParameter("count"));
        String image = request.getParameter("image");
        params.put("press",press);
        params.put("date",date);
        params.put("author",author);
        params.put("count",count);
        params.put("image",image);
        BookMapperFactory bmf = new BookMapperFactory();
        BookMapper bm =bmf.getMapper();
        bm.addBook(params);
        bmf.closeSession();
    }
}
